import { getDropDragData } from 'api';
import {
  DropDragAction,
  InitValues,
  DragRowSame,
  DragRowDiff,
} from '../reducers/drop-drag';
import { RootThunkAction } from 'store';

const dropDragAction = (payload: InitValues): DropDragAction => {
  return {
    type: '/drop-drag',
    payload,
  };
};

export const dropDragActionAsync = (): RootThunkAction => {
  return async (dispatch) => {
    const res = (await getDropDragData()) as InitValues;
    dispatch(dropDragAction(res));
  };
};

export const dragColumn = (payload: string[]): DropDragAction => {
  return {
    type: '/drag-column',
    payload,
  };
};

export const dragRowSame = (payload: DragRowSame): DropDragAction => {
  return {
    type: '/drag-row-same',
    payload,
  };
};

export const dragRowDiff = (payload: DragRowDiff): DropDragAction => {
  return {
    type: '/drag-row-diff',
    payload,
  };
};
